--------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  C:/yourdirectory/logs/coalcons.log
  log type:  text
 opened on:  18 Jun 2016, 19:02:20

. 
. set more off

. set matsize 1000

. 
. 
. *_______________________________________________________________________________
. 
. 
. /* Get monthly production and consumption data (thousand short tons) */
.    
. use "`dir_input'/eia_coalprodcons.dta", clear

. 
. tsset Counter
        time variable:  Counter, 1 to 488
                delta:  1 unit

. 
. gen delta_cons = Consumption-L.Consumption
(17 missing values generated)

. gen pct_cons = ln(Consumption/L.Consumption)
(17 missing values generated)

. 
. gen eventmonth = 0

. replace eventmonth = 1 if (Year==2010 & Month==4)
(1 real change made)

. 
. * Consumption regressions
. xi: ivreg2 pct_cons eventmonth, kernel(bartlett) bw(auto) small 

OLS estimation
--------------

Estimates efficient for homoskedasticity only
Statistics robust to autocorrelation
  kernel=Bartlett; bandwidth=    29
  Automatic bw selection according to Newey-West (1994)
  time variable (t):  Counter

                                                      Number of obs =      487
                                                      F(  1,   485) =     2.63
                                                      Prob > F      =   0.1053
Total (centered) SS     =  2.925313501                Centered R2   =   0.0054
Total (uncentered) SS   =  2.925923485                Uncentered R2 =   0.0056
Residual SS             =  2.909490994                Root MSE      =   .07745

------------------------------------------------------------------------------
    pct_cons |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
  eventmonth |  -.1259169   .0776063    -1.62   0.105     -.278403    .0265692
       _cons |   .0013777   .0010123     1.36   0.174    -.0006113    .0033668
------------------------------------------------------------------------------
Included instruments: eventmonth
------------------------------------------------------------------------------

. estimates store nofe

. xi: ivreg2 pct_cons eventmonth i.Month, kernel(bartlett) bw(auto) small 
i.Month           _IMonth_1-12        (naturally coded; _IMonth_1 omitted)

OLS estimation
--------------

Estimates efficient for homoskedasticity only
Statistics robust to autocorrelation
  kernel=Bartlett; bandwidth=    29
  Automatic bw selection according to Newey-West (1994)
  time variable (t):  Counter

                                                      Number of obs =      487
                                                      F( 12,   474) =   142.67
                                                      Prob > F      =   0.0000
Total (centered) SS     =  2.925313501                Centered R2   =   0.8383
Total (uncentered) SS   =  2.925923485                Uncentered R2 =   0.8383
Residual SS             =  .4730853545                Root MSE      =   .03159

------------------------------------------------------------------------------
    pct_cons |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
  eventmonth |  -.0482948   .0318985    -1.51   0.131    -.1109748    .0143851
   _IMonth_2 |   -.143387   .0074379   -19.28   0.000    -.1580024   -.1287717
   _IMonth_3 |  -.0206442   .0083726    -2.47   0.014    -.0370963   -.0041922
   _IMonth_4 |  -.0998738   .0087106   -11.47   0.000    -.1169899   -.0827577
   _IMonth_5 |   .0275699   .0082414     3.35   0.001     .0113757    .0437641
   _IMonth_6 |   .0535853   .0077953     6.87   0.000     .0382677    .0689029
   _IMonth_7 |    .070697   .0068049    10.39   0.000     .0573255    .0840685
   _IMonth_8 |  -.0220552   .0077946    -2.83   0.005    -.0373714    -.006739
   _IMonth_9 |  -.1358842   .0082911   -16.39   0.000    -.1521761   -.1195923
  _IMonth_10 |  -.0449647   .0087264    -5.15   0.000    -.0621118   -.0278175
  _IMonth_11 |  -.0251129   .0084183    -2.98   0.003    -.0416547   -.0085711
  _IMonth_12 |   .0705674   .0074811     9.43   0.000     .0558673    .0852675
       _cons |   .0236294   .0054934     4.30   0.000      .012835    .0344239
------------------------------------------------------------------------------
Included instruments: eventmonth _IMonth_2 _IMonth_3 _IMonth_4 _IMonth_5
                      _IMonth_6 _IMonth_7 _IMonth_8 _IMonth_9 _IMonth_10
                      _IMonth_11 _IMonth_12
------------------------------------------------------------------------------

. estimates store monthfe

. xi: ivreg2 pct_cons eventmonth i.Month i.Year, kernel(bartlett) bw(auto) small  
i.Month           _IMonth_1-12        (naturally coded; _IMonth_1 omitted)
i.Year            _IYear_1973-2013    (naturally coded; _IYear_1973 omitted)

OLS estimation
--------------

Estimates efficient for homoskedasticity only
Statistics robust to autocorrelation
  kernel=Bartlett; bandwidth=    29
  Automatic bw selection according to Newey-West (1994)
  time variable (t):  Counter

                                                      Number of obs =      487
                                                      F( 52,   434) =    31.24
                                                      Prob > F      =   0.0000
Total (centered) SS     =  2.925313501                Centered R2   =   0.8427
Total (uncentered) SS   =  2.925923485                Uncentered R2 =   0.8428
Residual SS             =  .4600986846                Root MSE      =   .03256

------------------------------------------------------------------------------
    pct_cons |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
  eventmonth |  -.0521753   .0357194    -1.46   0.145    -.1223799    .0180294
   _IMonth_2 |  -.1434121   .0077485   -18.51   0.000    -.1586413   -.1281829
   _IMonth_3 |  -.0206693   .0087249    -2.37   0.018    -.0378176    -.003521
   _IMonth_4 |  -.0998042    .009084   -10.99   0.000    -.1176584     -.08195
   _IMonth_5 |   .0275448   .0085729     3.21   0.001     .0106953    .0443944
   _IMonth_6 |   .0535602   .0081005     6.61   0.000     .0376392    .0694813
   _IMonth_7 |   .0706719   .0070665    10.00   0.000     .0567831    .0845607
   _IMonth_8 |  -.0220802   .0081003    -2.73   0.007     -.038001   -.0061595
   _IMonth_9 |  -.1357605   .0086316   -15.73   0.000    -.1527254   -.1187955
  _IMonth_10 |  -.0448409   .0091011    -4.93   0.000    -.0627287   -.0269532
  _IMonth_11 |  -.0249892   .0087759    -2.85   0.005    -.0422377   -.0077407
  _IMonth_12 |   .0706911    .007793     9.07   0.000     .0553745    .0860077
 _IYear_1974 |  -.0067357   .0073723    -0.91   0.361    -.0212255    .0077541
 _IYear_1975 |   .0035743   .0067364     0.53   0.596    -.0096658    .0168144
 _IYear_1976 |   .0057072   .0065179     0.88   0.382    -.0071033    .0185177
 _IYear_1977 |  -.0058565   .0064949    -0.90   0.368    -.0186219    .0069089
 _IYear_1978 |   .0036723   .0064949     0.57   0.572    -.0090931    .0164376
 _IYear_1979 |   .0020369   .0064949     0.31   0.754    -.0107285    .0148023
 _IYear_1980 |   .0005711   .0064949     0.09   0.930    -.0121942    .0133365
 _IYear_1981 |  -.0000792   .0064949    -0.01   0.990    -.0128446    .0126862
 _IYear_1982 |  -.0086285   .0064949    -1.33   0.185    -.0213939    .0041368
 _IYear_1983 |   .0109579   .0064949     1.69   0.092    -.0018075    .0237232
 _IYear_1984 |  -.0051107   .0064949    -0.79   0.432    -.0178761    .0076547
 _IYear_1985 |   .0059772   .0064949     0.92   0.358    -.0067881    .0187426
 _IYear_1986 |  -.0084525   .0064949    -1.30   0.194    -.0212179    .0043129
 _IYear_1987 |    .003165   .0064949     0.49   0.626    -.0096004    .0159304
 _IYear_1988 |     .00184   .0064949     0.28   0.777    -.0109254    .0146054
 _IYear_1989 |   .0036651   .0064949     0.56   0.573    -.0091003    .0164304
 _IYear_1990 |   -.006137   .0064949    -0.94   0.345    -.0189024    .0066283
 _IYear_1991 |  -.0041022   .0064949    -0.63   0.528    -.0168676    .0086631
 _IYear_1992 |   .0002906   .0064949     0.04   0.964    -.0124747     .013056
 _IYear_1993 |   .0006755   .0064949     0.10   0.917    -.0120899    .0134409
 _IYear_1994 |  -.0058349   .0064949    -0.90   0.369    -.0186002    .0069305
 _IYear_1995 |   .0032842   .0064949     0.51   0.613    -.0094811    .0160496
 _IYear_1996 |   .0015792   .0064949     0.24   0.808    -.0111862    .0143446
 _IYear_1997 |   .0002189   .0064949     0.03   0.973    -.0125464    .0129843
 _IYear_1998 |  -.0062449   .0064949    -0.96   0.337    -.0190103    .0065205
 _IYear_1999 |  -.0022439   .0064949    -0.35   0.730    -.0150092    .0105215
 _IYear_2000 |   .0045763   .0064949     0.70   0.481    -.0081891    .0173417
 _IYear_2001 |  -.0084421   .0064949    -1.30   0.194    -.0212075    .0043233
 _IYear_2002 |   .0033789   .0064949     0.52   0.603    -.0093865    .0161443
 _IYear_2003 |   .0005041   .0064949     0.08   0.938    -.0122613    .0132695
 _IYear_2004 |  -.0007197   .0064949    -0.11   0.912    -.0134851    .0120457
 _IYear_2005 |  -.0020514   .0064949    -0.32   0.752    -.0148168     .010714
 _IYear_2006 |  -.0046774   .0064949    -0.72   0.472    -.0174428     .008088
 _IYear_2007 |  -.0010039   .0064949    -0.15   0.877    -.0137692    .0117615
 _IYear_2008 |  -.0049951   .0064949    -0.77   0.442    -.0177604    .0077702
 _IYear_2009 |  -.0034102    .006495    -0.53   0.600    -.0161757    .0093553
 _IYear_2010 |   .0027838   .0072463     0.38   0.701    -.0114584    .0170261
 _IYear_2011 |    -.01685   .0064943    -2.59   0.010    -.0296143   -.0040857
 _IYear_2012 |  -.0029112   .0064922    -0.45   0.654    -.0156712    .0098488
 _IYear_2013 |   .0049491   .0086595     0.57   0.568    -.0120707    .0219689
       _cons |   .0246564   .0072624     3.40   0.001     .0103826    .0389302
------------------------------------------------------------------------------
Included instruments: eventmonth _IMonth_2 _IMonth_3 _IMonth_4 _IMonth_5
                      _IMonth_6 _IMonth_7 _IMonth_8 _IMonth_9 _IMonth_10
                      _IMonth_11 _IMonth_12 _IYear_1974 _IYear_1975 _IYear_1976
                      _IYear_1977 _IYear_1978 _IYear_1979 _IYear_1980
                      _IYear_1981 _IYear_1982 _IYear_1983 _IYear_1984
                      _IYear_1985 _IYear_1986 _IYear_1987 _IYear_1988
                      _IYear_1989 _IYear_1990 _IYear_1991 _IYear_1992
                      _IYear_1993 _IYear_1994 _IYear_1995 _IYear_1996
                      _IYear_1997 _IYear_1998 _IYear_1999 _IYear_2000
                      _IYear_2001 _IYear_2002 _IYear_2003 _IYear_2004
                      _IYear_2005 _IYear_2006 _IYear_2007 _IYear_2008
                      _IYear_2009 _IYear_2010 _IYear_2011 _IYear_2012
                      _IYear_2013
------------------------------------------------------------------------------

. estimates store yearfe

. 
. 
. local specif_list "nofe monthfe yearfe"

. 
. foreach specif of local specif_list{
  2.         /* obtain residuals so can do SQ test and normality tests */
.         estimates restore `specif'
  3.         predict resid_`specif', residual
  4.         *egen std_resid_`specif'  = std(resid_`specif')
. 
.         * save residuals for taking into Excel
.         save "`dir_output'/temp_results.dta", replace
  5.         drop if eventmonth==1
  6.         keep resid_*
  7.         *xpose, clear varname
.         save "`dir_output'/resids.dta", replace
  8.         use "`dir_output'/temp_results.dta"  /* get all variables back */       
  9.         
.         drop if eventmonth==1
 10.         * Shapiro-Wilk test for normality
.         swilk resid_`specif'
 11.         * Jarque-Bera test for normality
.         jb6 resid_`specif'
 12.         use "`dir_output'/temp_results.dta", clear  /* get all variables back */        
 13. }
(results nofe are active now)
(17 missing values generated)
(note: file C:/yourdirectory/output/coal_cons/temp_results.dta not found)
file C:/yourdirectory/output/coal_cons/temp_results.dta saved
(1 observation deleted)
(note: file C:/yourdirectory/output/coal_cons/resids.dta not found)
file C:/yourdirectory/output/coal_cons/resids.dta saved
(1 observation deleted)

                   Shapiro-Wilk W test for normal data

    Variable |    Obs       W           V         z       Prob>z
-------------+--------------------------------------------------
  resid_nofe |    486    0.98347      5.421     4.058    0.00002
Jarque-Bera normality test:  12.17 Chi(2)  .0023
Jarque-Bera test for Ho: normality: (resid_nofe)
(results monthfe are active now)
(17 missing values generated)
file C:/yourdirectory/output/coal_cons/temp_results.dta saved
(1 observation deleted)
file C:/yourdirectory/output/coal_cons/resids.dta saved
(1 observation deleted)

                   Shapiro-Wilk W test for normal data

    Variable |    Obs       W           V         z       Prob>z
-------------+--------------------------------------------------
resid_mont~e |    486    0.98732      4.156     3.420    0.00031
Jarque-Bera normality test:  41.56 Chi(2)  9.4e-10
Jarque-Bera test for Ho: normality: (resid_monthfe)
(results yearfe are active now)
(17 missing values generated)
file C:/yourdirectory/output/coal_cons/temp_results.dta saved
(1 observation deleted)
file C:/yourdirectory/output/coal_cons/resids.dta saved
(1 observation deleted)

                   Shapiro-Wilk W test for normal data

    Variable |    Obs       W           V         z       Prob>z
-------------+--------------------------------------------------
resid_yearfe |    486    0.98740      4.131     3.405    0.00033
Jarque-Bera normality test:  37.56 Chi(2)  7.0e-09
Jarque-Bera test for Ho: normality: (resid_yearfe)

. 
. drop if eventmonth==1
(1 observation deleted)

. 
. 
. /* Plot density of residuals and original variable*/
. kdensity resid_yearfe, generate(x_resid_base y_resid_base) nograph                      

. keep x_* y_*

. save "`dir_output'/kdensity_base.dta", replace
(note: file C:/yourdirectory/output/coal_cons/kdensity_base.dta not found)
file C:/yourdirectory/output/coal_cons/kdensity_base.dta saved

. use "`dir_output'/temp_results.dta"  /* get all variables back */       

. drop if eventmonth==1
(1 observation deleted)

. kdensity pct_cons, generate(x_var y_var) nograph                        

. keep x_* y_*

. save "`dir_output'/kdensity_originalvar.dta", replace
(note: file C:/yourdirectory/output/coal_cons/kdensity_originalvar.dta not found)
file C:/yourdirectory/output/coal_cons/kdensity_originalvar.dta saved

. use "`dir_output'/temp_results.dta"  /* get all variables back */       

. 
. log close
      name:  <unnamed>
       log:  C:/yourdirectory/logs/coalcons.log
  log type:  text
 closed on:  18 Jun 2016, 19:02:24
--------------------------------------------------------------------------------------------------------------------------
